Ext.namespace("Ext.un");
Ext.un.JsonReaderMutiSelGrid = function(meta, recordType){
    meta = meta || {};
    Ext.un.JsonReaderMutiSelGrid.superclass.constructor.call(this, meta, recordType || meta.fields);
};
Ext.extend(Ext.un.JsonReaderMutiSelGrid,Ext.data.JsonReader,{
	  extractData : function(root, returnRecords) {
        
        var rawName = (this instanceof Ext.data.JsonReader) ? 'json' : 'node';

        var rs = [];

        
        
        if (this.isData(root) && !(this instanceof Ext.data.XmlReader)) {
            root = [root];
        }
        var f       = this.recordType.prototype.fields,
            fi      = f.items,
            fl      = f.length,
            rs      = [];
        if (returnRecords === true) {
            var Record = this.recordType;
            for (var i = 0; i < root.length; i++) {
                var n = root[i];
                var recDataTmp = this.extractValues(n, fi, fl);
                var curId = 0;
                if(recDataTmp.id){
                	curId = recDataTmp.id;
                }else{
                	curId = this.getId(n);
                }
                var record = new Record(recDataTmp, curId);
                record[rawName] = n;    
                rs.push(record);
            }
        }
        else {
            for (var i = 0; i < root.length; i++) {
                var data = this.extractValues(root[i], fi, fl);
                data[this.meta.idProperty] = this.getId(root[i]);
                rs.push(data);
            }
        }
        return rs;
    }
});


Ext.un.JsonStoreMutiSelGrid = Ext.extend(Ext.data.Store, {
    constructor: function(config){
        Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
            reader: new Ext.un.JsonReaderMutiSelGrid(config)
        }));
    }
});

Ext.un.ArrayStoreExt = Ext.extend(Ext.data.Store, {
    constructor: function(config){
        Ext.data.ArrayStore.superclass.constructor.call(this, Ext.apply(config, {
            reader: new Ext.data.ArrayReader(config)
        }));
    },

    loadData : function(data, append){
        
            var r = [];
            for(var i = 0, len = data.length; i < len; i++){
                r[r.length] = [data[i]];
            }
            data = r;
        
        Ext.data.ArrayStore.superclass.loadData.call(this, data, append);
    },
    load : function(options){
    	this.loadData(this.data.items.data);
    }
});
